/**
 * 关于中间件嵌套，回调函数问题
 * @param fn
 */


function appPost(fn){
    var req = {
        content:"req..."
    }
    var res = "res.."
    if(fn){
        fn(req,res)
    }
}




// 一个简单的中间件
//返回一个类(req,res,next)=>{}函数
function middleware(fn){
    return (req, res) => {

        if(fn){
            fn(req.content, res)
        }
    }

}

//demo1：
appPost(middleware(function(req, res){
    console.log(req,res)
}))



//demo2:

function Wechat(fn){
    this.data = "data..."
    this.send = send
    this.run = run

    function run(fn){
        return (req, res) => {
            req.wx = this.data
            if(fn){
                fn(req, res)
            }
        }
    }

    function send(msg){
        console.log("msg: ",msg)
    }

}


var wechat = new Wechat

appPost(wechat.run(function(req, res){
    console.log("wechat:",req.content,res)
    wechat.send(req.wx)
}))


